import pandas as pd
import numpy as np
import plotly.express as px
import plotly.graph_objects as go
import pandas as pd
import numpy as np
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()
import geopandas as gpd
import requests
import io
url='https://raw.githubusercontent.com/nica-monica/Forestry-and-biodiversity-in-Sweden/main/age_counties_protected.csv'
download = requests.get(url).content
# Reading the downloaded content and turning it into a pandas dataframe
df_prot = pd.read_csv(io.StringIO(download.decode('utf-8')))
df.head()
| Unnamed: 0 | Year | County | Region | Type of Forest | Yearly growth | Average Age | Clear-cut Percent | 3-10 years Percent | 11 - 20 years Percent | 21 - 30 years Percent | 31 - 40 years Percent | 41 - 60 years Percent | 61 - 80 years Percent | 81 - 100 years Percent | 101 - 120 years Percent | 121 - 140 years Percent | 141+ years Percent | Old Forest 100 120 140* | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 315 | 2005 | Stockholm | Svealand | Protected | 7.11 | 82.8 | 4.7 | 3.1 | 4.1 | 0.0 | 0.0 | 19.7 | 23.8 | 6.2 | 13.5 | 18.7 | 7.3 | 39.5 |
| 1 | 316 | 2005 | Uppsala | Svealand | Protected | 6.66 | 78.8 | 3.1 | 0.0 | 0.0 | 10.1 | 6.1 | 26.3 | 11.8 | 7.9 | 13.2 | 9.2 | 12.7 | 21.9 |
| 2 | 317 | 2005 | Södermanland | Svealand | Protected | 7.72 | 54.8 | 24.1 | 0.0 | 0.0 | 6.5 | 8.3 | 17.6 | 16.7 | 7.4 | 4.6 | 13.9 | 0.0 | 18.5 |
| 3 | 318 | 2005 | Östergötland | Svealand | Protected | 7.96 | 82.5 | 0.0 | 0.0 | 0.0 | 9.2 | 0.0 | 14.9 | 39.1 | 13.8 | 0.0 | 16.1 | 8.0 | 24.1 |
| 4 | 319 | 2005 | Jönköping | Götaland | Protected | 7.15 | 56.8 | 0.0 | 4.0 | 8.0 | 21.3 | 17.3 | 6.7 | 16.0 | 17.3 | 0.0 | 10.7 | 0.0 | 10.7 |
import json
url = 'https://raw.githubusercontent.com/nica-monica/Forestry-and-biodiversity-in-Sweden/main/sweden-counties_1680.geojson'
resp = requests.get(url)
j = resp.json()
# j = json.loads(back_geojson)
fig = px.choropleth_mapbox(df_prot, geojson=j, locations='County',
color='Average Age',
color_continuous_scale="rdylgn",
featureidkey="properties.NAME_1",
animation_frame='Year',
range_color=(40, 100),
mapbox_style="carto-positron",
zoom=3.5, center = {"lat": 63, "lon": 14},
opacity=0.7,
labels={'Biodiversity by County'}
)
fig.update_layout(autosize=True,
width=600,
height=800,
margin=dict(l=50,r=50,b=100,t=100,pad=1))
fig.update_layout(
title={
'text': '<b>Average Age of Living Trees - Protected Areas','y':0.95,'x':0.45,'xanchor': 'center',
'yanchor': 'top'})
fig.update_traces(showlegend=False, showscale=False)
url='https://raw.githubusercontent.com/nica-monica/Forestry-and-biodiversity-in-Sweden/main/age_counties_unprotected.csv'
download = requests.get(url).content
df_unprot = pd.read_csv(io.StringIO(download.decode('utf-8')))
fig = px.choropleth_mapbox(df_unprot, geojson=j, locations='County',
color='average age',
color_continuous_scale="rdylgn",
featureidkey="properties.NAME_1",
animation_frame='Year',
range_color=(40, 100),
mapbox_style="carto-positron",
zoom=3.5, center = {"lat": 63, "lon": 14},
opacity=0.7,
labels={'Biodiversity by County'}
)
fig.update_layout(autosize=True,
width=600,
height=800,
margin=dict(l=50,r=50,b=100,t=100,pad=1))
fig.update_layout(
title={
'text': '<b>Average Age of Living Trees - Exploited Areas','y':0.95,'x':0.45,'xanchor': 'center',
'yanchor': 'top'})
fig.update_traces(showlegend=False, showscale=False)